package com.ruoyi.generator.controller;

import java.util.List;

import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.generator.domain.GenTableColumnSql;
import com.ruoyi.generator.service.GenTableColumnSqlService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.constant.HttpStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;

/**
 * 代码生成业务字段Controller
 *
 * @author 众智汇云研发部
 * @date 2021-11-23
 */

@Api(value = "代码生成业务字段管理", tags = "代码生成业务字段管理")
@RestController
@RequestMapping("/sql")
public class GenTableColumnSqlController extends BaseController {

    @Autowired
    protected GenTableColumnSqlService genTableColumnSqlService;

    /**
     * 查询代码生成业务字段列表
     */
    @ApiOperation(value = "查询代码生成业务字段列表", notes = "根据代码生成业务字段进行筛选", tags = "CRUD")
    @PreAuthorize("@ss.hasPermi('generator:sql:list')")
    @GetMapping("/list")
    public TableDataInfo list(GenTableColumnSql genTableColumnSql) {
        startPage();
        List<GenTableColumnSql> list = genTableColumnSqlService.selectGenTableColumnSqlList(genTableColumnSql);
        return getDataTable(list);
    }

    /**
     * 获取代码生成业务字段详细信息
     */
    @ApiOperation(value = "获取代码生成业务字段详细信息", notes = "根据ID获取详情", tags = "CRUD")
    @PreAuthorize("@ss.hasPermi('generator:sql:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam("编号") @PathVariable("id") Long id) {
        return AjaxResult.success(genTableColumnSqlService.selectGenTableColumnSqlById(id));
    }

    /**
     * 新增代码生成业务字段
     */
    @ApiOperation(value = "新增代码生成业务字段", response = HttpStatus.class,tags = "CRUD")
    @PreAuthorize("@ss.hasPermi('generator:sql:add')")
    @Log(title = "代码生成业务字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GenTableColumnSql genTableColumnSql) {
        return toAjax(genTableColumnSqlService.insertGenTableColumnSql(genTableColumnSql));
    }

    /**
     * 修改代码生成业务字段
     */
    @ApiOperation(value = "修改代码生成业务字段", response = HttpStatus.class,tags = "CRUD")
    @PreAuthorize("@ss.hasPermi('generator:sql:edit')")
    @Log(title = "代码生成业务字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GenTableColumnSql genTableColumnSql) {
        return toAjax(genTableColumnSqlService.updateGenTableColumnSql(genTableColumnSql));
    }

    /**
     * 删除代码生成业务字段
     */
    @ApiOperation(value = "删除代码生成业务字段", response = HttpStatus.class,tags = "CRUD")
    @PreAuthorize("@ss.hasPermi('generator:sql:remove')")
    @Log(title = "代码生成业务字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam("编号") @PathVariable Long[] ids) {
        return toAjax(genTableColumnSqlService.deleteGenTableColumnSqlByIds(ids));
    }

    /**
     * 导出代码生成业务字段列表
     */
    @ApiOperation(value="导出代码生成业务字段列表",response = HttpStatus.class)
    @PreAuthorize("@ss.hasPermi('generator:sql:export')")
    @Log(title = "代码生成业务字段", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GenTableColumnSql genTableColumnSql) {
        List<GenTableColumnSql> list = genTableColumnSqlService.selectGenTableColumnSqlList(genTableColumnSql);
        ExcelUtil<GenTableColumnSql> util = new ExcelUtil<GenTableColumnSql>(GenTableColumnSql.class);
        return util.exportExcel(list, "sql");
    }
}
